package com.huadao.pda.modle;

import android.content.Context;

import com.huadao.pda.base.BaseHttpModel;
import com.huadao.pda.data.bean.DeviceInfo;
import com.huadao.pda.data.bean.SweepCode;
import com.huadao.pda.data.http.Api;
import com.huadao.pda.data.http.HttpFunction;
import com.huadao.pda.data.http.RetrofitHelper;

import io.reactivex.Observable;

public class DeviceInfoModle extends BaseHttpModel {
    private Api api;

    public DeviceInfoModle(Context context) {
        api=RetrofitHelper.getInstance(context).create(Api.class);
    }

    public Observable<DeviceInfo> createAsync(String macAddress, int type){
        DeviceInfo deviceInfo=new DeviceInfo();
        deviceInfo.setMacAddress(macAddress);
        deviceInfo.setType(type);
        return api.createDevice(deviceInfo).map(new HttpFunction());
    }

    public Observable<DeviceInfo> getDeviceById(String id){
        return api.getDeviceById(id).map(new HttpFunction());
    }

    public Observable<Boolean> swapLogin(String projectId,String devInfoId,String code){
        SweepCode sweepCode=new SweepCode();
        sweepCode.setProjectId(projectId);
        sweepCode.setDevInfoId(devInfoId);
        sweepCode.setCode(code);
        return api.sweepCodeLogin(sweepCode).map(new HttpFunction());
    }
}
